Dir.chdir File.dirname(__FILE__) + "/.."
namespace :specs do
  ALL_SPECS = FileList['specs/**/*.rb']
  RCOV_OPTS = ['--exclude', 'specs,Library'] # Stop rspec and rcov are getting reported as well
  
  desc "Run all examples"
  Spec::Rake::SpecTask.new(:run) do |t|
    t.spec_files = ALL_SPECS
  end
  
  desc "Generate SpecDocs to doc/specs.txt"
  Spec::Rake::SpecTask.new(:doc) do |t|
    t.spec_files = ALL_SPECS
    t.spec_opts = ["--format", "specdoc:doc/specs.txt"]
  end
  
  desc "Generate HTML Spec to doc/specs.html"
  Spec::Rake::SpecTask.new(:html) do |t|
    t.spec_files = ALL_SPECS
    t.spec_opts = ["--format", "html:doc/specs.html"]
  end
  
  desc "Generate a code coverage report with rcov"
  Spec::Rake::SpecTask.new(:coverage) do |t|
    t.spec_files = ALL_SPECS
    t.rcov = true
    t.rcov_opts = RCOV_OPTS
  end
  
  desc "HTML report & RCov"
  Spec::Rake::SpecTask.new(:html_and_coverage) do |t|
    t.spec_files = ALL_SPECS
    t.rcov = true
    t.rcov_opts = RCOV_OPTS
    t.spec_opts = ["--format", "html:doc/specs.html"]
  end
  
  desc "Use stakeout to run specs whenever a file changes"
  task :auto do
    sh "stakeout 'rake specs:run' **/*.rb *.rb"
  end
  
  desc "Clean up generated spec docs"
  task :clean do
    FileUtils.rm "docs/specs.txt" if File.exists? "docs/specs.txt"
  end
end